package Eyjafjalla.power;

import Eyjafjalla.action.ExhaustToHandAction;
import Eyjafjalla.patch.CloudPatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.DamageRandomEnemyAction;
import com.megacrit.cardcrawl.actions.common.GainBlockAction;
import com.megacrit.cardcrawl.actions.common.RemoveSpecificPowerAction;
import com.megacrit.cardcrawl.actions.utility.UseCardAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.cards.DamageInfo;
import com.megacrit.cardcrawl.core.AbstractCreature;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.helpers.ImageMaster;
import com.megacrit.cardcrawl.localization.PowerStrings;

import java.util.ArrayList;

public class FollowHeartPower extends AbstractEyjafjallaPower {
    public static final String POWER_ID = "eyjafjalla:FollowHeartPower";
    private static final PowerStrings powerStrings;
    boolean toHand;
    ArrayList<AbstractCard> cards;
    private static int bombIdOffset;

    public FollowHeartPower(AbstractCreature owner, ArrayList<AbstractCard> cards, boolean toHand){
        this.name = powerStrings.NAME;
        this.ID = POWER_ID + bombIdOffset;
        ++bombIdOffset;
        this.owner = owner;
        if(cards!=null){
            this.amount = cards.size();
        }
        this.toHand = toHand;
        this.cards = cards;
        this.updateDescription();
        String path128 = "EyjafjallaResources/img/power/FollowHeartPower_84.png";
        String path48 = "EyjafjallaResources/img/power/FollowHeartPower_32.png";
        this.region128 = new TextureAtlas.AtlasRegion(ImageMaster.loadImage(path128),0,0,84,84);
        this.region48 = new TextureAtlas.AtlasRegion(ImageMaster.loadImage(path48),0,0,32,32);
        this.type = PowerType.BUFF;
    }

    @Override
    public void atEndOfRound() {
        this.flash();
        addToBot(new ExhaustToHandAction(toHand,cards));
        addToBot(new RemoveSpecificPowerAction(this.owner,this.owner,this));
    }

    @Override
    public void updateDescription() {
        StringBuilder des = new StringBuilder(powerStrings.DESCRIPTIONS[0]);
        for(int i =0;i<cards.size();i++){
            des.append(powerStrings.DESCRIPTIONS[3]).append(cards.get(i).name);
            if(i!=cards.size()-1)
                des.append(powerStrings.DESCRIPTIONS[4]);
        }
        if(toHand)
            des.append(powerStrings.DESCRIPTIONS[2]);
        else
            des.append(powerStrings.DESCRIPTIONS[1]);
        this.description = des.toString();
    }

    static {
        powerStrings = CardCrawlGame.languagePack.getPowerStrings(POWER_ID);
    }
}





